<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/home/include/init_home.jsp" %>
<%@ page import="com.qbooks.store.book.*" %>
<%
	String book_code		= StringUtil.nvl(request.getParameter("book_code"));

	if ("".equals(book_code)) {
		book_code = StringUtil.nvl(request.getAttribute("book_code"));
	}

	StoreDAO dao 			= new StoreDAO();
	

	HashMap param 			= new HashMap();
	param.put("book_code",	book_code);


	HashList info 			= dao.selectBookInfo(param);
	HashList reviewList		= dao.selectBookReviewList(param);
	
	//param.put("category_code", info.get("category_code",0));
	//HashList categoryInfo	= dao.selectCategoryInfo(param);

	
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title><%= HOME_NAME %></title>
	<%@ include file="/home/include/cssnjs.jsp"  %>

	<script type="text/javascript">

	$(document).ready(function() {
		$('span.rate').mouseover(function(){
			var curTitle = $(this).attr('title');
			$('span.rate').each(function(){
				if ($(this).attr('title') <= curTitle) {
					$(this).text('★');
				} else {
					$(this).text('☆');
				}
			});
		})

	});


	function btnPuchase() {
		$('#saveForm').attr('action', './bookPurchase.do');
		$('#saveForm').submit();
	}

	
	function btnReviewSave() 
	{
		var intRate = 0;
		$('span.rate').each(function(){
			if ($(this).text() == '★') {
				if ($(this).attr('title') > intRate) {
					intRate = $(this).attr('title');
				}
			}
		});

		if (intRate == 0) {
			alert('평점을 선택하세요');
			return false;
		} 

		$.ajax({
			url: './reviewSave.do',
			type: "POST",
		    dataType: 'json',
		    data:{ 
		    	book_code:'<%=book_code%>',
		    	rate:intRate, 
		    	review_info:$('#review_info').val() 
		    },
		    error: function(data, status, err){
		    	alert(err);
		    },
			success: function(data){
				if (data.result) {
					alert('성공');
				} else {
					alert(data.message);
				}
		    }
		});
	}
	
	function btnReviewCancel() {
		$("span.rate").text("☆");
		$("textarea[name='review_info']").text("");
		$("#review").hide();
	}

	</script>
</head>
<body>
	<div id="wrap">
	
		<%@ include file="/store/include/header.jsp"  %>
		
		<div id="contents">

			<h2>큐북서점</h2>
			
			<div id="book">
			
				<div id="book_image">
					<img src="<%= info.get("book_image_url",0) %>" width="200px"/>
				</div>
				<div id="book_info">
					<h2><%= info.get("book_name",0) %></h2>
					<p class="sub_title"><%= info.get("sub_title",0) %></p>
	
					<p><%= info.get("author_name",0) %> 저</p>
					<p><%= info.get("publisher_name",0) %>, <%= StringUtil.toDate(info.get("publish_dt",0),".") %> 발행</p>
					<p><%= info.get("download_count",0) %> 다운로드</p>
					<br/>
				<%	if ("0".equals(info.get("book_type",0))) { %>
						<span class="download_book">
							무료 다운로드 
						</span>
						<label>※ 큐북스앱에서 다운로드 가능합니다.</label>
				<%	} else { %>
						<div class="ui-btn ui-input-btn ui-btn-active ui-corner-all ui-shadow">
							<%= info.getPrice("price",0) %>원 구매하기
							<input type="button" alt="구매하기" value="구매하기" onclick="fnPurchaseBook()"/>
						</div>
				<%	} %>
					
				</div>
				<div class="clear"></div>
				
				
				<h3 class="mt30">설명</h3>
				<p><%= info.get("intro", 0) %></p>


				<h3>목차</h3>
				<p><%= StringUtil.toHTML(info.get("index_info", 0)) %></p>
				
		<%	if (!"".equals(info.get("author_info",0))) { %>
				<h3>저자 정보</h3>
				<p><%= StringUtil.toHTML(info.get("author_info", 0)) %></p>
		<%	} %>

				<!-- 
				<div class="mt20">
					<div>
						<h3 class="inline">리뷰</h3>
					<%	if (isLogin) { %>
							<a href="#nohref" onclick="$('#review').toggle()">리뷰작성</a>
					<%	} %>
					</div>
					<hr></hr>
					<div>
						<form name="reviewForm" id="reviewForm" method="post" action="./reviewSave.do">
						<div id="review" class="none">
							<table>
								<tr>
									<td width="100px">
										<%=session_user_name %>
									</td>
									<td>
										<textarea name="review_info" id="review_info" style="width:560px; height:80px"></textarea>
										<span class="rate" title="1">☆</span>
										<span class="rate" title="2">☆</span>
										<span class="rate" title="3">☆</span>
										<span class="rate" title="4">☆</span>
										<span class="rate" title="5">☆</span>
										<input type="button" value="리뷰등록" onclick="btnReviewSave()"/>
										<input type="button" value="취소" onclick="btnReviewCancel()"/>
									</td>
								</tr>
							</table>
						</div>
						</form>
					</div>
		<%		for (int i = 0; i < reviewList.size(); i++) { %>
					<div>
						<%= reviewList.get("member_name",i) %>[<%= reviewList.get("rate",i) %>]
						<%= reviewList.get("review_info",i) %>
						<%= reviewList.get("init_date",i) %>
					</div>
		<%		} %>
				</div>
				 -->
			</div>
		  
	</div>
	<%@ include file="/home/include/footer.jsp" %>
</div>
</body>
</html>
